/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-25
 * Time: 12:27
 */
public class test3 {
    /**'
     * LeetCode 1047  删除字符串中所有相邻的重复项
     */

    public String removeDuplicates(String S) {
        StringBuffer ret = new StringBuffer();
        char[] s = S.toCharArray();
        for(char ch:s){
            if(ret.length()>0 && ch==ret.charAt(ret.length()-1)){
                ret.deleteCharAt(ret.length()-1);
            }else{
                ret.append(ch);
            }
        }

        return ret.toString();
    }
}
